{include file="../_meta" /}

<body style="padding:0px;">
<!-- 添加用户窗口-->
<style>
	form {
		padding:20px 40px;
	}
	input {
		width:316px;
	}
</style>


<form id="ff" class="easyui-form" method="post">
	<input type="hidden" id="id" name="id" value="{$id}" />
	<div style="margin-bottom:10px;margin-top:10px;">
		<input class="easyui-textbox" id="employee_no" name="employee_no" data-options="label:'工&emsp;&emsp;号:',required:true,prompt:'请输入工号',missingMessage:'必填项'">
	</div>
	<div style="margin-bottom:10px;">
		<input class="easyui-textbox" name="employee_name" data-options="label:'姓&emsp;&emsp;名:',required:true,prompt:'请输入姓名',missingMessage:'必填项'">
	</div>
	<div style="margin-bottom:10px;">
		<input class="easyui-textbox" name="departs" data-options="label:'部&emsp;&emsp;门:',required:true,prompt:'请输入部门',missingMessage:'必填项'">
	</div>
	<div style="margin-bottom:10px;">
		<input class="easyui-textbox" name="departs_section" data-options="label:'科&emsp;&emsp;室:',required:true,prompt:'请输入科室',missingMessage:'必填项'">
	</div>
	<div style="margin-bottom:10px;">
		<input class="easyui-textbox" name="section_room" data-options="label:'车&emsp;&emsp;间:',required:true,prompt:'请输入车间',missingMessage:'必填项'">
	</div>
	<div style="margin-bottom:10px;">
		<input class="easyui-datebox" text="text" name="join_date" label="入职时间:"  data-options="formatter:myformatter,parser:myparser,required:true,panelWidth:220,prompt:'请选择入职时间',missingMessage:'必填项'">
	</div>
	<div>
		<input class="easyui-textbox" name="memo" style="height:100px;" data-options="multiline:true,label:'备&emsp;&emsp;注:'">
	</div>
</form>	
<div style="text-align:center;">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser();" style="margin-right:30px;">保存</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:parent.$('#dlg').dialog('close');">取消</a>
</div>	
	
<script type="text/javascript">
var id = $("#id").val();
if(id != '0') {
	$('#ff').form('clear');
	$('#ff').form('load', 'employeeUser?employee_id='+id);
}

// 判断JS变量是否为空
function isEmpty(data){ 
	return (data == "" || data == undefined || data == null || data.length == 0) ? true : false; 
}

$('#employee_no').textbox({  
    onChange: function(newValue, oldValue) {	
		//alert('new'+newValue); alert('old'+oldValue);
		if(isEmpty(newValue)) {
			//alert('new333'+newValue);
			return false;
		} else {
			//alert('new2'+newValue);
			$.ajax({  
				type : "post",  
				url : 'employeeCheckNo',  
				data : {'employee_no': newValue,'id': id}, 
				success : function(data) {  
						_data = eval("(" + data + ")");  
						console.info(_data);
						if(!_data.code) {
							var _title = 'Error';
							if(id == '0') {
								$('#employee_no').textbox('setValue', '');
							} else {
								$('#employee_no').textbox('setValue', oldValue);
							}							
							$('#employee_no').next('span').find('input').focus();
						} else {
							var _title = 'Success';
						}
						parent.$.messager.show({
							title: _title,
							msg:  _data.errorMsg
						});
					}  
			}); 
		}
		
		
    }
});

// 保存用户
function saveUser() {
	var id = $("#id").val();
	var msg = "修改成功!";
		if(id == '0'){
			msg = "添加成功!"
		}
	$('#ff').form('submit',{
		url: "employeeSave",
		onSubmit: function(){
			return $(this).form('enableValidation').form('validate');
		},
		success: function(result){			
			var result = eval('('+result+')');
			if (result.errorMsg){
				parent.$.messager.show({
					title: 'Error',
					msg: result.errorMsg
				});
			} else {				
				
				parent.$.messager.show({
					title: 'Success',
					msg:  msg,
				});
	
				parent.$('#dlg').dialog('close')
				parent.$('#easyui_dg').datagrid('reload');	// reload the user data
			}
		}
	});
};
</script>			
</body>
</html>